#!/bin/sh
. ./properties

if [ "$PROJECT_NAME" == "" -o "$PROJECT_DESC" == "" -o "$PROJECT_GUID" == "" -o "$AUTHOR" == "" ];then 
	echo "Please check README file. Probably you forgot to define some of variables"
	exit
fi

#create directory structure
mkdir -p content/"$PROJECT_NAME"
mkdir -p chrome/
mkdir -p defaults/preferences/
touch defaults/preferences/default.js
mkdir -p skin/classic/"$PROJECT_NAME"


#replace templates with proper files
cat templates/install_template.js | sed -e "s/\$PROJECT_NAME/$PROJECT_NAME/g" -e "s/\$AUTHOR/$AUTHOR/g" > install.js
cat templates/install_template.rdf | sed -e "s/\$PROJECT_GUID/$PROJECT_GUID/g" -e "s/\$PROJECT_NAME/$PROJECT_NAME/g" -e "s/\$PROJECT_HOMEPAGE/$PROJECT_HOMEPAGE/g" -e "s/\$AUTHOR/$AUTHOR/" -e "s/\$PROJECT_DESC/$PROJECT_DESC/" > install.rdf
cat templates/about_template.xul | sed -e "s/\$PROJECT_NAME/$PROJECT_NAME/g" -e "s/\$PROJECT_HOMEPAGE/$PROJECT_HOMEPAGE/g" -e "s/\$AUTHOR/$AUTHOR/g" > content/$PROJECT_NAME/about.xul
cat templates/option_template.xul | sed -e "s/\$PROJECT_NAME/$PROJECT_NAME/g" > content/$PROJECT_NAME/option.xul
cat templates/contents_jar_template.rdf | sed -e "s/\$PROJECT_NAME/$PROJECT_NAME/g" -e "s/\$AUTHOR/$AUTHOR/g" -e "s/\$AUTHOR_MAIL/$AUTHOR_MAIL/g" -e "s/\$PROJECT_DESC/$PROJECT_DESC/g" > content/$PROJECT_NAME/contents.rdf
touch content/$PROJECT_NAME/"$PROJECT_NAME"Overlay.xul
cat templates/contents_template.rdf | sed -e "s/\$PROJECT_NAME/$PROJECT_NAME/g" > skin/classic/$PROJECT_NAME/contents.rdf
touch content/$PROJECT_NAME/"$PROJECT_NAME"Overlay.xul

#place addon icon into proper place

if [ ! -f "images/$PROJECT_NAME.png" ];then
	exit
fi
cp images/$PROJECT_NAME.png skin/classic/$PROJECT_NAME/$PROJECT_NAME.png
